<?php

namespace app\common\model;

use app\common\model\BaseModel as BaseModel;

/**
 * Class ConsultingServerSku
 * @package app\common\model
 * @property int	$id
 * @property int	$consultingServerId
 * @property int	$isChatFreely
 * @property int	$chatFreelyDuration
 * @property int	$questionsNum
 * @property int	$isShowCallTel
 * @property int	$showCallTelDuration
 * @property string	$dataIcon
 * @property string	$icon
 * @property string	$name
 * @property float	$showPrice
 * @property float	$price
 * @property string	$desc1
 * @property string	$desc2
 * @property string	$desc3
 * @property int	$updated
 * @property int	$created
 * @property int	$deleted
 * @link https://www.kancloud.cn/manual/thinkphp6_0/1037579
 * @link https://www.kancloud.cn/manual/think-orm/1257998
 * @link https://www.kancloud.cn/thinkphp/master-database-and-model/265551
 */
class ConsultingServerSku extends BaseModel
{
    protected $name = 'ConsultingServerSku';

    // 图标
    public function getIconImgAttr($value, $data)
    {
        return image_url($data['icon'] ?? '', 'min');
    }

    // 统计图标
    public function getDataIconImgAttr($value, $data)
    {
        return image_url($data['dataIcon'] ?? '', 'min');
    }

    public function getQuestionsNumStrAttr($value, $data)
    {
        if ($data['isChatFreely'] == 1) {
            return '赠送' . humanized_time_length($data['chatFreelyDuration'] * 3600) . '畅聊';
        } elseif ($data['questionsNum'] > 0) {
            return '赠送' . $data['questionsNum'] . '次聊天';
        } else {
            return '';
        }
    }

    /**
     * 1对1
     * @return \think\model\relation\HasOne
     */
    //    public function one(){
    //        return $this->hasOne( Test1::class, 'Test1表中的键', 'ConsultingServerSku表中的键');
    //    }

    /**
     * 1对多
     * @return \think\model\relation\HasMany
     */
    //    public function many(){
    //        return $this->hasMany( Test1::class, 'Test1表中的键', 'ConsultingServerSku表中的键');
    //    }

    /**
     * 多对多
     * @return \think\model\relation\BelongsToMany
     */
    //    public function belongs(){
    //        return $this->belongsToMany( Test1::class, '中间表', '中间表中Test1的键', '中间表中ConsultingServerSku的键');
    //    }
}
